\documentclass[10pt,a4paper]{article} 

\usepackage{ctex} % 中文支持
\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry} % 页边距
\usepackage{amsmath, amssymb} % 数学公式与符号
\usepackage{graphicx}
\usepackage{pythonhighlight}
\usepackage{url} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 使用Tikz
\usepackage{tikz}
\usetikzlibrary{graphs,arrows.meta}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 使表格美观
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\setlength\extrarowheight{3pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titling}
\setlength{\droptitle}{-2cm} % 标题上移

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%文档的题目、作者与日期
\author{五六七 }
\title{公司信用分类与神经网络模型 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

\begin{abstract}
使用神经网络模型对上市公司的信用等级进行分类。
\end{abstract}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\setcounter{tocdepth}{2}
%\renewcommand\contentsname{目录}
%
%\renewcommand {\baselinestretch} {1.3}\normalsize 
%\tableofcontents 
%\renewcommand {\baselinestretch} {1.0}\normalsize


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{问题描述}
我国沪深两市的上市公司分为非ST公司和ST公司。
一般来说，非ST公司的信用等级较高，ST公司的等级较低。
为了有效评价上市公司的信用等级，考察一些相关的评价指标，如表所示。

\begin{table}[ht!]\centering
\caption{变量名称与含义} \vspace{0.2cm}
\begin{tabular}{|p{1.5cm}|p{4cm}|}\hline
变量名 & 含义   \\ \hline 
$x_1$ &流动比率  \\ \hline 
$x_2$ &负债比率  \\ \hline 
$x_3$ &存货周转期 \\ \hline 
$x_4$ &总资产周转率  \\ \hline 
$x_5$ &净资产收益率  \\ \hline 
$x_6$ &每股收益率   \\ \hline 
$x_7$ &总利润增长率  \\ \hline 
$x_8$ &每股经营现金流量  \\ \hline 
\end{tabular}
\end{table}

已知训练样本和待判样本的数据如表所示，其中类别1表示ST公司，类别0表示非ST公司。使用神经网络模型，对待判样本进行分类。

\begin{table}[ht!]\centering
\caption{上市公司信用评价指标数据 } \vspace{0.2cm}
\begin{tabular}{|p{1cm}|p{1cm}|p{1cm}|p{1cm}|p{1.2cm}|p{1cm}|p{1cm}|p{1cm}|p{1cm}|p{1cm}|}\hline
序号 & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ & $x_6$ & $x_7$ & $x_8$ & 类别 \\ \hline 
1	&	0.404	&	39.15	&	15.55	&	10.75	&	0.524	&	3.645	&	2.395	&	0.31	&	0		\\ \hline 
2	&	1.263	&	54.17	&	6.13	&	19.47	&	2.198	&	10.336	&	0.495	&	0.118	&	0		\\ \hline 
3	&	0.871	&	11.88	&	6.98	&	-18.22	&	0.481	&	16.146	&	6.385	&	0.624	&	0		\\ \hline 
4	&	1.317	&	20.38	&	13.13	&	57.79	&	0.299	&	19.396	&	1.937	&	0.673	&	0		\\ \hline 
5	&	0.722	&	9.33	&	10.09	&	10.22	&	0.444	&	2.515	&	17.564	&	0.3	&	0		\\ \hline 
6	&	-0.195	&	26.28	&	0.95	&	-7.59	&	0.292	&	0.596	&	4.78	&	0.015	&	1		\\ \hline 
7	&	0.329	&	22.76	&	1.74	&	-56.57	&	0.357	&	0.543	&	3.238	&	0.087	&	1		\\ \hline 
8	&	-0.001	&	269.39	&	-20.85	&	44.49	&	0.093	&	3.466	&	0.123	&	-0.329	&	1		\\ \hline 
9	&	-0.222	&	73.68	&	2.04	&	106.73	&	0.654	&	3.157	&	0.841	&	0.021	&	1		\\ \hline 
10	&	0.005	&	42.77	&	-4.15	&	-205.21	&	0.472	&	2.622	&	1.882	&	-0.048	&	1		\\ \hline 
11	&	1.564	&	59.86	&	-9.22	&	-313.31	&	0.284	&	1.565	&	1.444	&	-0.102	&	待判		\\ \hline 
12	&	0.74	&	13.27	&	6.14	&	-7.3	&	0.554	&	18.406	&	5.631	&	0.482	&	待判		\\ \hline 
\end{tabular}
\end{table}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{单层感知器}
设有输入 $x_1,x_2,\cdots,x_n$, 输出 $y$, 单层感知器的数学模型为 
\begin{eqnarray}
\left\{\begin{array}{rcl}
u &=& w_1x_1 + w_2x_2 + \cdots + w_nx_n = w^tx, \\ 
v &=& u+b, \\ 
y &=& f(v). 
\end{array}\right.
\end{eqnarray}
写成一个公式，就是
\begin{eqnarray}
y = f(w_1x_1 + w_2x_2 + \cdots + w_nx_n + b). 
\end{eqnarray}
其中 $w_1,w_2,\cdots,w_n$ 称为权重，$b$ 是截距，$f$ 称为激活函数。如图所示。

\begin{center}
\tikz{
\node [circle, draw] (x1) at (0,3) {$x_1$}; 
\node [circle, draw] (x2) at (0,2) {$x_2$}; 
\node [circle, draw] (xn) at (0,0) {$x_n$}; 
\node [circle, draw] (u) at (2,2) {$u$}; 
\node [circle, draw] (v) at (4,2) {$v$}; 
\node [circle, draw] (y) at (6,2) {$y$}; 
\graph {(x1) ->  (u) };
\graph {(x2) ->  (u) };
\graph {(xn) ->  (u) };
\graph {(u) ->  (v) };
\graph {(v) ->  (y) };
}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{激活函数}

激活函数是使得神经网络模型可以拟合非线性数据的关键因素。激活函数有以下几种。

\begin{enumerate} 
\item  线性函数 $f(v)=kv+c$. 
\item  非线性斜面函数 $f(v)=\left\{\begin{array}{ll}
\gamma, & v\ge \theta, \\ 
kv, & |v|<\theta, \\ 
-\gamma, & v\le -\theta. 
\end{array}\right. $

\item  阈值函数 $f(v) = \left\{\begin{array}{ll}
\beta, & v> \theta, \\ 
-\gamma, & v\le -\theta. 
\end{array}\right. $

\item  Sigmond函数 $f(v) = \frac{1}{1+e^{-v}}$. 

\item  双曲正切函数 $f(v) = \tanh (v) = \frac{e^v-e^{-v}}{e^v+e^{-v}}$. 

\item  ReLU 函数 $f(v) = \left\{\begin{array}{ll}
v, & v\ge 0, \\ 
0, & v< 0. 
\end{array}\right. $

\end{enumerate} 



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{例子15.10的问题描述}

设有四个已知分类的输入向量，求新输入向量的分类。

\begin{table}[ht!]\centering
\caption{例子15.10的数据 } \vspace{0.2cm}
\begin{tabular}{|M{2cm}|M{2cm}|M{2cm}|M{2cm}|}\hline
编号 & 第1分量 & 第2分量 & 分类 \\ \hline 
1 & $-0.5$ & $-0.5$ & 1  \\ \hline 
2 & $-0.5$ & $0.5$ & 1  \\ \hline 
3 & $0.3$ & $-0.5$ & 0 \\ \hline 
4 & $0.0$ & $1.0$ & 0 \\ \hline 
5 & $-0.5$ & $0.2$ & ?  \\ \hline 
\end{tabular}
\end{table}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage

\section{例子15.10 的程序计算 }

载入sklearn程序包的单层感知器函数。
\begin{python}
from sklearn.linear_model import Perceptron
import numpy as np
\end{python}

输入训练数据。
\begin{python}
x0=np.array([[-0.5,-0.5,0.3,0.0],[-0.5,0.5,-0.5,1.0]]).T
y0=np.array([1,1,0,0])
\end{python}

构造并拟合模型。
\begin{python}
md = Perceptron().fit(x0,y0)   
\end{python}

输出模型系数和常数项。
\begin{python}
print(md.coef_)
print(md.intercept_)  
\end{python}

输出模型精度。
\begin{python}
print(md.score(x0,y0))
\end{python}

输出模型预测。
\begin{python}
print(md.predict([[-0.5,0.2]]))
\end{python}

输出结果：

\begin{python}
模型系数和常数项分别为： [[-1.3 -0.5]] , [0.]
模型精度： 1.0
预测值为： [1]
\end{python}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{神经网络}
一个神经网络就是在输入变量和输出变量之间有很多层的中间变量，并且变量之间用线性组合和激活函数连接起来的一个数学模型。例如图1中的神经网络。

\begin{center}
\tikz{

\node [circle, draw] (x1) at (0,3) {$x_1$}; 
\node [circle, draw] (x2) at (0,2) {$x_2$}; 
\node [circle, draw] (x3) at (0,1) {$x_3$}; 
\node [circle, draw] (x4) at (0,0) {$x_4$}; 
\node [circle, draw] (z11) at (2,2) {$z_{11}$}; 
\node [circle, draw] (z12) at (2,1) {$z_{12}$}; 
\node [circle, draw] (z13) at (2,0) {$z_{13}$}; 
\node [circle, draw] (z21) at (4,2) {$z_{21}$}; 
\node [circle, draw] (z22) at (4,1) {$z_{22}$}; 
\node [circle, draw] (z23) at (4,0) {$z_{23}$}; 
\node [circle, draw] (y1) at (6,1) {$y_1$}; 
\node [circle, draw] (y2) at (6,0) {$y_2$}; 

\graph {(x1) ->  (z11) };
\graph {(x1) ->  (z12) };
\graph {(x1) ->  (z13) };

\graph {(x2) ->  (z11) };
\graph {(x2) ->  (z12) };
\graph {(x2) ->  (z13) };

\graph {(x3) ->  (z11) };
\graph {(x3) ->  (z12) };
\graph {(x3) ->  (z13) };

\graph {(x4) ->  (z11) };
\graph {(x4) ->  (z12) };
\graph {(x4) ->  (z13) };

\graph {(z11) ->  (z21) };
\graph {(z11) ->  (z22) };
\graph {(z11) ->  (z23) };

\graph {(z12) ->  (z21) };
\graph {(z12) ->  (z22) };
\graph {(z12) ->  (z23) };

\graph {(z13) ->  (z21) };
\graph {(z13) ->  (z22) };
\graph {(z13) ->  (z23) };

\graph {(z21) ->  (y1) };
\graph {(z21) ->  (y2) };
\graph {(z22) ->  (y1) };
\graph {(z22) ->  (y2) };
\graph {(z23) ->  (y1) };
\graph {(z23) ->  (y2) };

}
\end{center}

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{BP神经网络}
一个BP神经网络就是的相邻层之间是全连接，每层内部无连接。
按照有监督方式进行学习，即调整每个连接的权重参数。
输入数据通过网络向右传播，到达输出数据，与已有观测比较，把误差向左传播，调整参数，使得减小误差。
BP神经网络模型在手写数字识别任务中取得了很好的效果\cite{nips1989}。
BP神经网络的具体算法如下。

\vspace{0.3cm}

\begin{minipage}{0.9\textwidth}

\makebox[\linewidth]{\rule{\textwidth}{0.5pt}}

%\renewcommand{\labelenumii}{\theenumii}
%\renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}
%%\setlength{\leftmarginii}{3ex}
%\setlength{\leftmarginii}{1.5ex}

\begin{enumerate}
\item  每个连接权重 $w_{ij}$ 和阈值 $\theta_{ij}$ 随机在 $[-1,1]$ 中初始化赋值。
\item  随机选择一对观测数据 $(X_0,Y_0)=(x_{10},x_{20},x_{30},x_{40},y_{10},y_{20} )$. 
\item  
%\stepcounter{enumi}
\begin{enumerate}
\item[3.1.]  使用输入数据 $X_0$, 使用权重 $w_{ij}$ 和阈值 $\theta_{ij}$ 计算中间层各单元的输出。
\item[3.2.]  计算输出层各单元的响应 $d_j$. 
\item[3.3.]  计算输出层各单元的误差 $e_j$. 
\item[3.4.]  计算中间层各单元的误差 $f_j$. 
\item[3.5.]  调整连接权重 $w_{ij}$ 和阈值 $\theta_{ij}$. 
\end{enumerate}

\item  随机选择另一对观测数据。重复上面的第3步。
\item  当全局误差小于预先给定的值，学习结束，此时网络收敛。
\end{enumerate}
\makebox[\linewidth]{\rule{\textwidth}{0.5pt}}
\vspace{0.3cm}
\end{minipage}
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{数据预处理}

第一种归一化将数据映射到区间 $[0,1]$ 中，使用函数 $$\tilde{x} = \frac{x-x_{\text{min}}}{x_{\text{max}}-x_{\text{min}}}.$$ 
第二种归一化将数据映射到区间 $[-1,1]$ 中，使用函数 
$$\tilde{x} = \frac{2(x-x_{\text{min}})}{x_{\text{max}}-x_{\text{min}}} -1.$$ 
第三种归一化将数据化为均值为零、方差为一的数据，使用函数 
$$\tilde{x} = \frac{x-\bar{x}}{s},$$ 
其中 $\bar{x}$ 和 $s$ 分别是数据 $x$ 的均值和标准差。用Python计算标准差时，参数 ddof=0,1是指delta自由度， 分别是采用下述两种计算公式
$$
s = \sqrt{ \frac{1}{n} \sum\limits_{i=1}^n (x_i-\bar{x})^2}, \,\, 
s = \sqrt{ \frac{1}{n-1} \sum\limits_{i=1}^n (x_i-\bar{x})^2}. 
$$



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{编程计算}

载入多层感知器函数。
\begin{python}
from sklearn.neural_network import MLPClassifier
import numpy as np
\end{python}

载入数据，提出训练样本和待判样本数据。
\begin{python}
a = np.loadtxt('data15_11.txt')
x0 = a[:10,:]
x = a[10:,:]  
\end{python}

计算逐列最大值和最小值。
\begin{python}
m1 = x0.max(axis=0); m2 = x0.min(axis=0)  
\end{python}

数据标准化。
\begin{python}
bx0 = (x0-m2)/(m1-m2)  
\end{python}

变量x2的数值特殊处理。
\begin{python}
bx0[:,1] = (m1[1]-x0[:,1])/(m1[1]-m2[1])   
\end{python}

根据已知分类，赋予标号值。
\begin{python}
y0 = np.hstack([np.zeros(5), np.ones(5)])  
\end{python}

构造并拟合一个多层感知器分类模型。
\begin{python}
md = MLPClassifier(solver='lbfgs',activation='logistic', hidden_layer_sizes=30).fit(bx0, y0)
\end{python}
                   
待判样本数据标准化。
\begin{python}
bx = (x-m2) / (m1-m2)  
\end{python}

变量x2的数值特殊处理。
\begin{python}
bx[:,1] = (m1[1]-x[:,1])/(m1[1]-m2[1])
\end{python}

用模型进行预测分类。
\begin{python}
yh = md.predict(bx)
\end{python}

打印待判样本的类别。
\begin{python}
print(yh)
\end{python}

打印属于各个类别的概率。
\begin{python}
print(md.predict_proba(bx))
\end{python}

打印训练样本的测试准确度。
\begin{python}
print(md.score(bx0, y0))
\end{python}

上述程序的输出结果：待判样本类别、属于各个类别的概率、训练样本的测试准确度，分别如下。
\begin{python}
[1. 0.]

 [[3.95200872e-03 9.96047991e-01]
 [9.99999608e-01 3.91557915e-07]]
 
1.0
\end{python}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{回答问题}
根据模型结果判断，第11号公司的类别为1，第12号公司的类别为0. 



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\section{参考文献 }
\begin{thebibliography}{99}

%\bibitem{dingtongren} 丁同仁、李承治，常微分方程教程，高等教育出版社，2022年3月第三版。
\bibitem{sishoukui-2} 司守奎,孙玺菁. \emph{Python数学建模算法与应用}, 国防工业出版社. 2022年1月第1版. 
%\bibitem{hexiaoqun-ara} 何晓群. \emph{应用回归分析(R语言版)}. 电子工业出版社. 2017年7月第1版. 
%\bibitem{dalgaard} Peter Dalgaard 著, 郝智恒等译. \emph{R语言统计入门}. 人民邮电出版社. 2014年6月第1版. 

\bibitem{shaham2016} 
Uri Shaham, Alexander Cloninger, and Ronald R. Coifman. 
\emph{Provable approximation properties for deep neural networks}. 
arxiv 1509.07385. March 2016. 

\bibitem{nips1989}
LeCun, Yann and Boser, Bernhard and Denker, John and Henderson, Donnie and Howard, R. and Hubbard, Wayne and Jackel, Lawrence. \emph{Handwritten Digit Recognition with a Back-Propagation Network},
Advances in Neural Information Processing Systems, Volume 2,1989. 

\end{thebibliography}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





